/**
 * 
 */
package belote.webapp.tools;

import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Gwenn
 *
 */
public class CookieReader {

	private Cookie[] cookies;
	
	public CookieReader(ServletRequest pRequest) {
		this((HttpServletRequest) pRequest);
	}
	
	public CookieReader(HttpServletRequest pRequest) {
		this.cookies = pRequest.getCookies();
	}
	
	public Cookie getCookie(String pName) {
		
		if (pName != null && cookies != null) {
			for (Cookie cookie : cookies) {
				if (cookie.getName().equals(pName)) {
					return cookie;
				}
			}
		}
		
		return null;
	}
}
